package com.sm.sales_management.controller;


import com.sm.sales_management.domain.Salesman;

import com.sm.sales_management.service.ISalesmanService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;

@Controller
@RequestMapping("/salesman")
public class SalesmanController {
    @Autowired
    ISalesmanService salesmanService;

    @RequestMapping("/allsalesman")
    public String allsalesman(Model model){
        List<Salesman> salesmanList=salesmanService.selectAllSaleman();
        model.addAttribute("salesmanlist",salesmanList);
        return "salesman_list";

    }

    @RequestMapping("/delsalesman{id}")
    public String delsalesman(@PathVariable("id") int id){
        salesmanService.delete(id);
        return "redirect:/salesman/allsalesman";
    }

    @RequestMapping("/toupdatesal")
    public String toupdatesal(){

        return "updatesalesman";
    }

    @RequestMapping("/updatesal")
    public String updatesal(Salesman salesman){
        salesmanService.updateSalesman(salesman);
        return "redirect:/salesman/allsalesman";
    }

    @RequestMapping("/toaddsal")
    public String toaddsal(){

        return "addsalesman";
    }

    @RequestMapping("/addsal")
    public String addsal(Salesman salesman){
        salesmanService.insertSaleman(salesman);
        return "redirect:/salesman/allsalesman";
    }
}
